package it.happyisland.framework.web.render;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class JsonArray extends Json{
	private List<Json> values = new ArrayList<Json>();
	
	public void add(Object o){
		Json json = Json.convert(o);
		values.add(json);
	}
	
	
	@Override
	public String toJson() {
		StringBuffer result = new StringBuffer();
        result.append("[");
        
        Iterator<Json> it = values.iterator();
        while(it.hasNext()) {
        	Json value = it.next();
            result.append(value.toJson());
            if(it.hasNext()) {
                result.append(",");
            }
        }
        result.append("]");
        return result.toString();
	}

}
